import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

# 生成日时间序列
dd = pd.date_range('2010-01-01', freq='D', periods=1000)
# print(f'生成日时间序列：\n{dd}')

stock_data = np.random.normal(loc=10.0, scale=1.0, size=1000)
# print("stock_data：\n {}".format(stock_data))

stock_data = np.around(stock_data, 2)  # 保留2位小数
# print("stock_data：\n {}".format(stock_data))

pct_change = np.around((stock_data - np.roll(stock_data, 1)) / np.roll(stock_data, 1), 2)
pct_change[0] = np.nan
# print("pct_change：\n {}".format(pct_change))

df_stock = pd.DataFrame({'close': stock_data, 'price range': pct_change}, index=dd)
# print(f'股价交易数据：\n {df_stock.head()}')#打印前5行数据

df_stock.close[100:150].plot(c='b')
plt.legend(['Close'], loc='best')
plt.show()
